package com.doumi.biz.qadev.api.util;

import java.util.*;

/**
 * Created by YDZ on 2019/9/25.
 */
public class ListUtils {
    /**
     * @param list
     * @param hashmap
     * @return 比较list和map的value的值是否匹配
     */
    public boolean listCompareMap(List<String> list, HashMap<String,String> hashmap){
        boolean result=false;
        if (list.size()!=hashmap.size()){
            return result;
        }else {
            Iterator iteratormap=hashmap.values().iterator();
            Iterator iteratorlist=list.iterator();
            while (iteratorlist.hasNext() &&iteratormap.hasNext()){
//                count++;
//                if (count==6){
//                System.out.println("iteratorlist.next():"+(iteratorlist.next() instanceof String)+"iteratormap.next():"+(iteratormap.next() instanceof String));}
                //当count=6时（iteratorlist.next()为一个时间戳），一个值为string类型，另一个为integer类型,改为转换为string比较
                if (String.valueOf(iteratorlist.next()).equals(String.valueOf(iteratormap.next()))){
                    result=true;
                }else {
                    result=false;
                    break;
                }
            }
            return result;
        }
    }

    /**
     * 当hashmap中有interger类型的数时，比较两个对象返回的为false
     * @param list
     * @param hashmap
     * @return
     */


    /**
     * 比较两个list
     * @param list
     * @param hashMapList
     * @return
     */
    public boolean listCompareMap(List<List<String>> list, List<HashMap<String,String>> hashMapList){
        if (list.size()!=hashMapList.size()){
            return false;
        }else {
            for (int i = 0; i <list.size() ; i++) {
                if (!listCompareMap(list.get(i),hashMapList.get(i))){
                    System.out.println("第"+i+"个元素不一致");
                    return false;
                }
            }
            return true;
        }
    }
    public List<List<String>> listCompareList(List<List<String>> list, List<List<String>> lists){
        List<List<String>> max =new ArrayList<>();
        List<List<String>> min =new ArrayList<>();
        Integer listsize=list.size();
        Integer listssize=lists.size();
        if (listsize>listssize){
            max=list;
            min=lists;
        }else {
            max=lists;
            min=list;
        }
        for (List<String> l:min
                ) {
            if (max.contains(l)){
                max.remove(l);
            }
        }
        return max;
    }
    public List<List<String>> listminList(List<List<String>> list, List<List<String>> lists){
        List<List<String>> max =new ArrayList<>();
        List<List<String>> min =new ArrayList<>();
        Integer listsize=list.size();
        Integer listssize=lists.size();
        if (listsize>listssize){
            max=list;
            min=lists;
        }else {
            max=lists;
            min=list;
        }
        for (List<String> l:max
                ) {
            if (min.contains(l)){
                min.remove(l);
            }
        }
        return min;
    }

    public  List<String> equals(List<String> cuIds,List<Integer> resurlt) {
        List<String> diffUserid = new ArrayList<String>();
        for (String userid: cuIds ) {
            for (Integer aResurlt : resurlt) {
                if (Objects.equals(aResurlt, Integer.valueOf(userid))) {
                    break;
                } else {
                    diffUserid.add(userid);
                }
            }
        }
        return diffUserid;
    }
}
